package com.ruoyi.web.controller.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 用户信息测试接口
 * 
 * @author ruoyi
 */
@Api(tags = "用户信息测试接口")
@RestController
@RequestMapping("/api/test/user")
public class UserTestController extends BaseController {
    
    @Autowired
    private ISysUserService userService;
    
    /**
     * 获取用户信息
     */
    @ApiOperation("获取用户信息")
    @GetMapping("/info/{userId}")
    @Anonymous // 允许匿名访问，无需登录认证
    public AjaxResult getUserInfo(
            @ApiParam(value = "用户ID", required = true, example = "1")
            @PathVariable("userId") Long userId) {
        SysUser user = userService.selectUserById(userId);
        if (user != null) {
            // 出于安全考虑，不返回敏感信息
            user.setPassword(null);
            return AjaxResult.success(user);
        } else {
            return AjaxResult.error("用户不存在");
        }
    }
    
    /**
     * 获取所有用户列表
     */
    @ApiOperation("获取所有用户列表")
    @GetMapping("/list")
    @Anonymous // 允许匿名访问，无需登录认证
    public AjaxResult getUserList() {
        SysUser user = new SysUser();
        return AjaxResult.success(userService.selectUserList(user));
    }
}